# _*_ coding:utf-8 _*_
# @Time  : 2022.09.21
# @Author: zizlee
import datetime

import requests
from urllib3 import disable_warnings
disable_warnings()


def get_indexes():
    # 读取网络指标数据，过滤并修改起始日期
    r = requests.get('https://210.13.218.130:9000/v1/datalib/table/indexGroups/', verify=False)
    customer_indexes = list(filter(lambda x: x['group'] == 'rj1', r.json()['data']))[0]
    return customer_indexes['data']


def checker(index_list):
    today = CHECK_DAY if CHECK_DAY else datetime.datetime.today().strftime('%Y-%m-%d')
    no_update = list(filter(lambda x: x['enddate'] and x['enddate'] < today, index_list))
    if len(no_update) < 1:
        print('今日数据已全更新！')
    else:
        for i in no_update:
            print(i)


if __name__ == '__main__':
    CHECK_DAY = '2023-12-19'
    indexes = get_indexes()
    exclude = ['R00021138', 'R00021149', 'R00021161', 'R00021164', 'R00021176', 'R00021179', 'R00021181', 'R00021199', 'R00021201']
    # exclude += [f'R00020{i}' for i in range(931, 940)]
    # 去除年月的指标
    indexes = list(filter(lambda x: x['frequency'] == '日', indexes))
    indexes = list(filter(lambda x: x['source_id'] not in exclude, indexes))
    # 去除期权的指标
    # indexes = list(filter(lambda x: not x['name_zh'].startswith('平值看'), indexes))
    # indexes = list(filter(lambda x: not x['name_zh'].startswith('历史波动率:'), indexes))
    # indexes = list(filter(lambda x: not x['name_zh'].startswith('基差:'), indexes))
    # 去除主力合约
    # indexes = list(filter(lambda x: x['name_zh'].find('主力合约') == -1, indexes))
    checker(indexes)
